import React from 'react'
import "./cateGoods.css"
import { reqShopAdd } from "../../../request/api";


function CateGoods(props) {
    let {cateGoods,history} = props

    let addShop=(id,e)=>{
        e.stopPropagation();
        reqShopAdd({uid:JSON.parse(sessionStorage.getItem("user")).uid,type:1,goodsid:id,num:1}).then(res=>{
            if(res.data.code===200){
                console.log("购物车添加成功");
            }
        })
    }
    
    return (
        <dl>
            <dt>时令蔬菜</dt>
            {
                cateGoods.map(item => (
                    <dd key={item.id} onClick={()=>history.push("/detail/"+item.id)}>
                        <div><img src={item.img} alt="" /></div>
                        <div className="cateGoodsBox">
                            <p className="goodsname">{item.goodsname}</p>
                            <p>现价<span className="price">￥{item.price}</span>&nbsp;原价<span className="market_price">￥{item.market_price}</span></p>
                            <p className="shop" onClick={(e)=>addShop(item.id,e)} >加入购物车</p>
                            <p className="description">{item.description}</p>
                        </div>
                    </dd>
                ))
            }
        </dl>
    )
}
export default React.memo(CateGoods)